|
|
|
|
|
|
|
What about the meanings of the individual constants and use of the SetWindowPos function? The declarations and purposes of this function and other specific API functions can be found in my book Dan Appleman's Visual Basic Programmer's Guide to the Win32 API or other Win32 API reference. That level of detail is simply beyond the scope of this book. |
|
|
|
|
|
|
|
|
Discovering Bits Using the AND Operator |
|
|
|
|
|
|
|
|
Let's say you wanted to obtain information about a window in the system. Does it have a border? Is it minimized or maximized? Does it have a vertical or horizontal scrollbar? The Win32 API could define separate functions for each of these questions, but that would be very inefficient. After all, each of these questions has a simple yes or no answer, which can be represented by a single bit. In fact, this information is stored internally to the Window as a 32-bit long value called the window style. You can retrieve this value using the GetWindowLong function as follows: |
|
|
|
|
|
|
|
|
Public Const GWL_STYLE = (-16)
Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
' Get the class info
style& = GetWindowLong&(useHwnd&, GWL_STYLE) |
|
|
|
|
|
|
|
|
Here are some of the available window styles: |
|
|
|
|
|
|
|
|
Public Const WS_MINIMIZE = &H20000000
Public Const WS_VISIBLE = &H10000000
Public Const WS_DISABLED = &H8000000
Public Const WS_MAXIMIZE = &H1000000
Public Const WS_BORDER = &H800000
Public Const WS_VSCROLL = &H200000
Public Const WS_HSCROLL = &H100000 |
|
|
|
|
|
|
|
|
Let's say you determine that a window has a style of &H1A00000. |
|
|
|
|
|
|
|
|
Can you determine if it has a horizontal scrollbar set? |
|
|
|
|
|
|
|
|
To do this, you need to be able to determine the value of a single bit. Let's start with a simple example. Take the number 5, or 101 (binary). Define three constants as follows: |
|
|
|
|
|
|
|
|
BIT0 = &H1
BIT1 = &H2
BIT2 = &H4 |
|
|
|
|
|